using System;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services.Protocols;
using SMS.GettingSportService;
using digit.Core;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GettingSportService : System.Web.Services.WebService
{
    public AuthHeader Authentication;

    public GettingSportService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    public class AuthHeader : SoapHeader
    {
        public string Username;
        public string Password;
    }

    //[SoapHeader("Authentication")]
    //[WebMethod]
    //public long SportServiceReceiver(long contentId, string serviceCode, string cupCode, string matchCode, string homeCode, string awayCode, string msg)
    //{
    //    //if (Authenticated())
    //    //{
    //    ServiceSportsInfo objInfo = new ServiceSportsInfo();
    //    long serId = 0;

    //    if (serviceCode.Replace(" ", "").Trim() != "")
    //    {
    //        if (serviceCode.Trim().ToLower() == "tyle")
    //        {
    //            objInfo.Cmd1 = Util.GetAppSettings("BET");
    //            objInfo.Cmd2 = "IMP";
    //            objInfo.Code1 = Util.GetAppSettings("TYLE");
    //            objInfo.Code2 = "TYLE";
    //            objInfo.Param1 = homeCode;
    //            objInfo.Param2 = awayCode;
    //            objInfo.Param3 = objInfo.Cmd1 + "_" + objInfo.Code1 + "_" + homeCode;
    //            objInfo.Param4 = "BET_" + "TL_" + awayCode;
    //            objInfo.ServiceID = "6298";
    //        }

    //        else if (serviceCode.Trim().ToLower() == "ketqua")
    //        {
    //            if (cupCode.Replace(" ", "") != "")
    //            {
    //                objInfo.Cmd1 = Util.GetAppSettings("BET");
    //                objInfo.Cmd2 = "IMP";
    //                objInfo.Code1 = Util.GetAppSettings("KETQUA");
    //                objInfo.Code2 = "KETQUA";
    //                objInfo.Param1 = cupCode;
    //                objInfo.Param3 = objInfo.Cmd1 + "_" + objInfo.Code1 + "_" + cupCode;
    //                objInfo.ServiceID = "6298";
    //            }
    //            else
    //            {
    //                objInfo.Cmd1 = Util.GetAppSettings("BET");
    //                objInfo.Cmd2 = "IMP";
    //                objInfo.Code1 = Util.GetAppSettings("KETQUA");
    //                objInfo.Code2 = "KETQUA";
    //                objInfo.Param1 = homeCode;
    //                objInfo.Param2 = awayCode;
    //                objInfo.Param3 = objInfo.Cmd1 + "_" + objInfo.Code1 + "_" + homeCode;
    //                objInfo.Param4 = objInfo.Cmd1 + "_" + objInfo.Code1 + "_" + awayCode;
    //                objInfo.ServiceID = "6598";
    //            }
    //        }
    //        else return 0;

    //        string[] values = msg.ToString().Split("$$".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
    //        string[] sContents = new string[5];
    //        int iCont = 0;

    //        for (int i = 0; i < values.Length; i++)
    //        {
    //            if (!values[i].ToString().Replace(" ", "").Equals(""))
    //            {
    //                sContents[iCont] = values[i].ToString();
    //                iCont++;
    //            }
    //        }

    //        objInfo.Content1 = sContents[0];
    //        objInfo.Content2 = sContents[1];
    //        objInfo.Content3 = sContents[2];
    //        objInfo.Content4 = sContents[3];
    //        objInfo.Content5 = sContents[4];

    //        byte j = 0;

    //        if (objInfo.Content1 != null && objInfo.Content1.Replace(" ", "") != "") j++;

    //        if (objInfo.Content2 != null && objInfo.Content2.Replace(" ", "") != "") j++;

    //        if (objInfo.Content3 != null && objInfo.Content3.Replace(" ", "") != "") j++;

    //        if (objInfo.Content4 != null && objInfo.Content4.Replace(" ", "") != "") j++;

    //        if (objInfo.Content5 != null && objInfo.Content5.Replace(" ", "") != "") j++;

    //        objInfo.NumOfMsg = j;

    //        objInfo.ContentType = 0;
    //        objInfo.MsgType = 1;
    //        objInfo.CreatedBy = "AutoUpdate";
    //        objInfo.CreatedDate = DateTime.Now;
    //        objInfo.Status = 1;

    //        try
    //        {
    //            if (contentId != -1 && contentId != 0)
    //            {
    //                objInfo.ServiceSportID = contentId;
    //                bool result = ServiceSportsManager.Update(objInfo);
    //                if (result) return contentId;
    //                else return -1;
    //            }
    //            else
    //                serId = ServiceSportsManager.Insert(objInfo);
    //        }
    //        catch { return -1; }
    //    }

    //    if (serId != 0) return serId;
    //    else
    //        return -1;
    //    //}
    //    //else
    //    //    return 98;
    //}

    [SoapHeader("Authentication")]
    [WebMethod]
    public DataSet GetAllSportContent()
    {
        DataSet ds = ServiceSportsManager.SelectAll();
        if (ds != null && ds.Tables[0].Rows.Count > 0)
            return ds;
        else
            return null;
    }

    [SoapHeader("Authentication")]
    [WebMethod]
    public DataSet GetAllSportContentToday()
    {
        DataSet ds = ServiceSportsManager.SelectServiceSportToday();
        if (ds != null && ds.Tables[0].Rows.Count > 0)
            return ds;
        else
            return null;
    }

    private bool Authenticated()
    {
        if (Authentication.Username == "GetSpotServ" && Authentication.Password == "P@sSPLReceiv") return true;
        else
            return false;
    }    
}
